package com.example.hello.controller;


import com.example.hello.model.Drink;
import com.example.hello.model.Student;
import com.example.hello.service.IDrinkService;
import com.example.hello.service.IStudentService;
import org.joda.money.CurrencyUnit;
import org.joda.money.Money;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.time.LocalDate;

@Controller
public class RouterController {
    //自动注入
    @Autowired
    public IDrinkService drinkService;
    @Autowired
    public IStudentService studentService;
    //处理根请求 返回manage下面的login页面
    @GetMapping("/")
    public String login(){
        return "manage/login";
    }

    @GetMapping("manage/index")
    public String index(){
        return "manage/index";
    }

    @GetMapping("manage/welcome")
    public String welcome(){
        return "manage/welcome";
    }

    @GetMapping("/menu/drink")
    public String drink(){
        return "drink/index";
    }


    //分类管理
    @GetMapping("/menu/category")
    public String category(){
        return "category/index";
    }

    @GetMapping("/category/addform")
    public String categoryaddform(){
        return "category/add";
    }


    @GetMapping("/drink/addform")
    public String adddrink(){
        return "drink/add";
    }

    @GetMapping("/drink/drinkupdateform")
    //get /drink/updateform/id=17
    public ModelAndView drinkupdateform(@RequestParam Integer id){
        ModelAndView mv=new ModelAndView("drink/edit");
        //TODO:通过id从数据库找到相应的数据
        Drink drink=drinkService.getDrinkById(id);
        mv.addObject("data",drink);
        return mv;
    }

    //学生管理系统
    @GetMapping("/menu/student")
    public String student(){
        return "student/index";
    }

    @GetMapping("/student/addform")
    public String adddstudent(){
        return "student/add";
    }

    @GetMapping("/student/studentupdateform")
    //get /drink/updateform/id=17
    public ModelAndView studentupdateform(@RequestParam Long id){
        ModelAndView mv=new ModelAndView("student/edit");
        //TODO:通过id从数据库找到相应的数据
        Student student=studentService.getStudentById(id);
        mv.addObject("data",student);
        return mv;
    }
}
